Consumer 接口
1 | public interface Consumer<T> { |
1 | public void happy(double money, Consumer<Double> consumer) { |
1 | happy(1000, money -> System.out.println("吃喝玩乐")); |
1 | happy(10000, money -> System.out.println("旅游")); |
Supplier 接口
1 | public interface Supplier<T> { |
1 | public List<Integer> getNumList(int num, Supplier<Integer> supplier) { |
1 | getNumList(10, () -> (int)(Math.random() * 100)) |
Function 接口
1 | public interface Function<T, R> { |
1 | public String strHandler(String str, Function<String, String> function) { |
1 | strHandler(" Lambda ", str -> str.trim().toUpperCase()) |
Predicate 接口
1 | public interface Predicate<T> { |
1 | public List<String> filterStr(List<String> list, Predicate<String> predicate) { |
1 | List<String> strings = Arrays.asList("Hello", "Lambda", "Function", "Java"); |